﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EntityModel;
using BusinessLayer;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PL___Web_Application
{
    public class PagesMethods : System.Web.UI.Page
    {
        public void CheckCookie()
        {
            HttpCookie cookie = Request.Cookies["cardealer"];
            if (cookie == null)
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected Business GetBusinessFromCookie()
        {
            HttpCookie cookie = Request.Cookies["cardealer"];
            if (cookie == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                String username = cookie["cardealer-username"];
                BL controller = new BL();
                return controller.getBusinessCustomer(username);
            }
            return null;
        }
        protected Private GetPrivateFromCookie()
        {
            HttpCookie cookie = Request.Cookies["cardealer"];
            if (cookie == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                String username = cookie["cardealer-username"];
                BL controller = new BL();
                return controller.getPrivateCustomer(username);
            }
            return null;
        }
        public void GetFuel(object sender, EventArgs e)
        {
            Label lb = (Label)sender;
            BL controller = new BL();
            lb.Text = controller.getFuelName(Convert.ToInt32(lb.Attributes["fuelid"]));
        }
        public void GetTypeCar(object sender, EventArgs e)
        {
            Label lb = (Label)sender;
            BL controller = new BL();
            lb.Text = controller.getCarTypeName(Convert.ToInt32(lb.Attributes["typecarid"]));
        }
    }
}